// 设置 rem 函数
function setRem(baseSize = 16, baseWidth = 1920) {
  // 当前页面宽度相对于 1920 宽的缩放比例，可根据自己需要修改。
  const scale = document.documentElement.clientWidth / baseWidth
  // 设置页面根节点字体大小
  document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + 'px'
}

const centerWidth = document.documentElement.clientWidth

// 初始化rem.js
// setRem(10, centerWidth)
if (centerWidth >= 2500) {
  barWidth = 30
  barHeight = 25
  setRem(16)
} else if (centerWidth < 2500 && centerWidth >= 1920) {
  barWidth = 20
  barHeight = 15
  setRem(16)
} else if (centerWidth < 1920 && centerWidth >= 1600) {
  barWidth = 18
  barHeight = 12
  setRem(14, centerWidth)
} else if (centerWidth < 1600 && centerWidth >= 1280) {
  barWidth = 15
  barHeight = 10
  setRem(10, centerWidth)
} else if (centerWidth < 1280 && centerWidth >= 900) {
  barWidth = 10
  barHeight = 8
  setRem(10, centerWidth)
} else {
  barWidth = 10
  barHeight = 8
  setRem(8, centerWidth)
}
// 改变窗口大小时重新设置 rem
window.onresize = function () {
  const width = document.documentElement.clientWidth
  if (width >= 2500) {
    barWidth = 30
    barHeight = 25
    setRem(16)
  } else if (width < 2500 && width >= 1920) {
    barWidth = 20
    barHeight = 15
    setRem(16)
  } else if (width < 1920 && width >= 1600) {
    barWidth = 18
    barHeight = 12
    setRem(14, width)
  } else if (width < 1600 && width >= 1280) {
    barWidth = 15
    barHeight = 10
    setRem(10, width)
  } else if (width < 1280 && width >= 900) {
    barWidth = 10
    barHeight = 8
    setRem(10, width)
  } else {
    barWidth = 10
    barHeight = 8
    setRem(8, width)
  }
}
